package com.smh.a02CalendarDemo2;

import java.util.Calendar;
import java.util.Date;

public class CalendarDemo {
    public static void main(String[] args) {

        //calendar是抽象类
        Calendar calendar = Calendar.getInstance();
        //把日期放在一个数组中
        System.out.println(calendar);
        //月份0-11对应1-12
        //星期 1(星期日) 2(星期一)
        Date date = new Date(0L);
        calendar.setTime(date);
        System.out.println(calendar);
        calendar.set(Calendar.YEAR,2000);
        calendar.set(Calendar.MONTH,11);
        calendar.set(Calendar.MONTH,888);//
        calendar.set(Calendar.DAY_OF_MONTH,9);
        //月份加一
        calendar.add(Calendar.MONTH,1);
        //月份建议
        calendar.add(Calendar.MONTH,-1);

        //0 纪元 1 年 2 月 3 一年中的第几周 4 一月中的第几周 5 一月中的第几天
        int year = calendar.get(Calendar.YEAR);
        int month = calendar.get(Calendar.MONTH)+1;
        int day = calendar.get(Calendar.DAY_OF_MONTH);
        int week = calendar.get(Calendar.DAY_OF_WEEK);

        System.out.println(year+","+month+","+day+","+getWeek(week));

    }

    //查表法
    public static String getWeek(int week){
        String[] arr = {"","星期日","星期一","星期二","星期三","星期四","星期五","星期六"};

        return arr[week];
    }
}
